<?php
/**
 * @desc 注册用户管理
 * @author kevin wang
 * @date 2014-09-20
 */
class ctrl_register extends ctrl_base {
    private static $dirName = 'register';

	//内部注册用户
	public static function inline(){
		if(!model_admin::islogin()) {
    		self::goto_login();
    	}
		self::operation(array('register_inline'));
		//页面输入参数处理
    	$currentPage = isset($_POST['pageNum']) ? $_POST['pageNum'] : 1;
    	$pagesize = isset($_POST['numPerPage']) ? $_POST['numPerPage'] : self::$_pagesize;
		$nextpage = ($currentPage - 1) * $pagesize;

		$username = isset($_POST['username']) ? trim($_POST['username']) : '';
    	$mobile = isset($_POST['mobile'])? trim($_POST['mobile']):'';
		$condition = array();
    	if($username != '') {
    		$condition['username'] = $username;
    	}
    	if($mobile != '') {
    		$condition['mobile'] = $mobile;
    	}

		//用户获取
    	$register_list = model_register :: registerInlineList($nextpage,$pagesize,$condition);
    	$total = array_pop($register_list);
		//模板赋值
    	self::smarty() -> assign('register_list', $register_list);
		self::smarty() -> assign('total', $total);
		self::smarty() -> assign('pageNum', $currentPage);
		self::smarty() -> assign('numPerPage', $pagesize);
		self::smarty() -> assign('pageNumShown', self::$_pageNumShown);
		self::smarty() -> assign('shoNum', self::$_shoNum);

		self::smarty() -> assign('username', $username);
		self::smarty() -> assign('mobile', $mobile);

    	self::smarty() -> display(self::$dirName . '/inline_list.html');

	}
	//外部注册用户
	public static function outline(){
		if(!model_admin::islogin()) {
    		self::goto_login();
    	}
		self::operation(array('register_outline'));
		//页面输入参数处理
    	$currentPage = isset($_POST['pageNum']) ? $_POST['pageNum'] : 1;
    	$pagesize = isset($_POST['numPerPage']) ? $_POST['numPerPage'] : self::$_pagesize;
		$nextpage = ($currentPage - 1) * $pagesize;

		$username = isset($_POST['username']) ? trim($_POST['username']) : '';
    	$mobile = isset($_POST['mobile'])? trim($_POST['mobile']):'';
		$condition = array();
    	if($username != '') {
    		$condition['username'] = $username;
    	}
    	if($mobile != '') {
    		$condition['mobile'] = $mobile;
    	}

		//用户获取
    	$register_list = model_register :: registerOutlineList($nextpage,$pagesize,$condition);
    	$total = array_pop($register_list);
		//模板赋值
    	self::smarty() -> assign('register_list', $register_list);
		self::smarty() -> assign('total', $total);
		self::smarty() -> assign('pageNum', $currentPage);
		self::smarty() -> assign('numPerPage', $pagesize);
		self::smarty() -> assign('pageNumShown', self::$_pageNumShown);
		self::smarty() -> assign('shoNum', self::$_shoNum);
		self::smarty() -> assign('username', $username);
		self::smarty() -> assign('mobile', $mobile);
    	self::smarty() -> display(self::$dirName . '/outline_list.html');
	}
	//内部注册用户信息查看
	public static function registerInlineCheck(){
		if(!model_admin::islogin()) {
    		self::goto_login();
    	}
		self::operation(array('register_inline_check'));
		$user_id = intval($_GET['id']);
		$inline = model_register::get_inline_user_info($user_id);
		$user_category = model_register::get_user_catecogry(1);
		self::smarty() -> assign('inline', $inline);
		self::smarty() -> assign('user_category', $user_category);
		self::smarty() -> display(self::$dirName . '/inline_check.html');
	}
	//内部注册用户编辑
	public static function registerInlineEdit(){
		if(!model_admin::islogin()) {
    		self::goto_login();
    	}
		self::operation(array('register_inline_edit'));
		if($_POST){
			$request = self::get_request_data();
			$sales_id = intval($_POST['sales_id']);
			$result = model_register::update_Inline_user($request, $sales_id);
			if(!empty($result)){
				self::ajax_ouput(200, '操作成功','register_inline','closeCurrent');
			}else{
				self::ajax_ouput(300, '操作失败');
			}
		}
		$user_id = intval($_GET['id'])?intval($_GET['id']):die("非法请求");
		$inline = model_register::get_inline_user_info($user_id);
		$user_category = model_register::get_user_catecogry(1);
		self::smarty() -> assign('inline', $inline);
		self::smarty() -> assign('user_category', $user_category);
		self::smarty() -> display(self::$dirName . '/inline_edit.html');
	}
	//外部注册用户编辑
	public static function registerOutlineCheck(){
		if(!model_admin::islogin()) {
    		self::goto_login();
    	}
		self::operation(array('register_outline_check'));
		$user_id = intval($_GET['id'])?intval($_GET['id']):die("非法请求");
		$outline = model_register::get_outline_user_info($user_id);
		$user_category = model_register::get_user_catecogry(2);
		self::smarty() -> assign('user_category', $user_category);
		self::smarty() -> assign('outline', $outline);
		self::smarty() -> display(self::$dirName . '/outline_check.html');
	}
	//外部注册用户编辑
	public static function registerOutlineEdit(){
		if(!model_admin::islogin()) {
    		self::goto_login();
    	}
		self::operation(array('register_outline_edit'));
		if($_POST){
			$request = self::get_request_data();
			$register_id = intval($_POST['register_user_id']);
			$result = model_register::update_Outline_user($request, $register_id);
			if(!empty($result)){
				self::ajax_ouput(200, '操作成功','register_outline','closeCurrent');
			}else{
				self::ajax_ouput(300, '操作失败');
			}
		}
		$user_id = intval($_GET['id'])?intval($_GET['id']):die("非法请求");
		$outline = model_register::get_outline_user_info($user_id);
		$user_category = model_register::get_user_catecogry(2);
		self::smarty() -> assign('user_category', $user_category);
		self::smarty() -> assign('outline', $outline);
		self::smarty() -> display(self::$dirName . '/outline_edit.html');
	}
	//外部用户审核
	public static function check_register_user(){
		if(!model_admin::islogin()) {
    		self::goto_login();
    	}
		self::operation(array('register_outline_check'));
		$request['register_user_id'] = intval($_POST['register_user_id'])?intval($_POST['register_user_id']):die("非法请求");
		$request['Deal_State'] = intval($_POST['Deal_State']);
		$request['Deal_msg'] = trim($_POST['Deal_msg']);
		$reflush = trim($_POST['reflush']);
		$result = model_register::check_user($request);
		if(!empty($result)){
			self::ajax_ouput(200, '操作成功',$reflush,'closeCurrent');
		}else{
			self::ajax_ouput(300, '操作失败');
		}
	}
	//内部用户审核
	public static function check_inline_user(){
		if(!model_admin::islogin()) {
    		self::goto_login();
    	}
		self::operation(array('register_inline_check'));
		$request['sales_id'] = isset($_POST['sales_id'])?intval($_POST['sales_id']):die("非法请求");
		$request['deal_state'] = intval($_POST['deal_state']);
		$request['deal_msg'] = trim($_POST['deal_msg']);
		$reflush = trim($_POST['reflush']);
		$result = model_register::check_inline_user($request);
		if(!empty($result)){
			self::ajax_ouput(200, '操作成功',$reflush,'closeCurrent');
		}else{
			self::ajax_ouput(300, '操作失败');
		}
	}
}
